package fun.flyee.android.pengshan.acts;

import android.os.Bundle;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;
import fun.flyee.android.pengshan.events.UnauthEvent;

public abstract class BaseActivity extends AppCompatActivity {

    abstract protected int layoutId();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutId());
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    @Subscribe
    public void whenUnauth(UnauthEvent ev) {
        if (!(this instanceof LoginActivity)) {
            Router.logout(this);
            finish();
        }
    }

}
